package com.wy.powerbuilder.controller.lwg;

import com.github.pagehelper.PageInfo;
import com.wy.powerbuilder.entity.ld.User;
import com.wy.powerbuilder.entity.lwg.houses;
import com.wy.powerbuilder.entity.lwg.owner;
import com.wy.powerbuilder.mapper.lwg.housesMapper;
import com.wy.powerbuilder.mapper.lwg.ownerMapper;
import com.wy.powerbuilder.service.lwg.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.SQLOutput;
import java.util.List;

@Controller
public class ownerConller {
@Autowired
private ownerMapper ownerMapper;
    @Autowired
    private StudentService studentService;
    @Autowired
    private com.wy.powerbuilder.mapper.lwg.housesMapper housesMapper;
    @Autowired
    private com.wy.powerbuilder.service.lwg.housesService housesService;
    /*@GetMapping("/users")
    List<owner> selAll(){
        return ownerMapper.selAll();
    };*/
            //查询
    @RequestMapping(value = {"/students","/"})
    public String selByPage(Integer pageNum, Model model, String o_state){
        //实现我们的分页  每页显示两条   pageInfo应该放在那里 model modelAndView map
        PageInfo<owner> pageInfo = studentService.selByPage(pageNum, 8,o_state);

        model.addAttribute("pageInfo",pageInfo);

        return "yezhuxx";
    }
    //删除
    @RequestMapping("/del")
    public String del(Integer o_id){
        int i = ownerMapper.delete(o_id);
        System.out.println(i);
        //删除成功是不是又要进行查询
        return "redirect:/students";
    }
    //添加
    @RequestMapping("/adds")
    public String add(Model model){
//查到房屋的编号
        List<houses> houses=housesService.linn();
        model.addAttribute("houses",houses);
        System.out.println(houses.get(0).getH_number());
        return "owneradd";
    }
//添加合同
    @RequestMapping("/addssa")
    public String add(owner Owner,Model model){
         int abc=Owner.getO_number();
        ownerMapper.addUser(Owner);
        houses Houses=housesMapper.zuih(abc);
        return "redirect:/students";
    }

    @RequestMapping("/upd")
    public String upd(owner Owner){
        ownerMapper.updStudent(Owner);
        return "redirect:/students";
    }

    //户主的修改
    //根据ID 查询
    @RequestMapping("ownerupdate")
    public String showUpdateAdmin(int o_id,Model model){
        owner Oser=studentService.showUser(o_id);
        model.addAttribute("Oser",Oser);
        return "linxg";
    }


//退租的修改
    //根据ID 修改
    @RequestMapping("ownerupdates")
    public String showUpdateAdm(int o_id,Model model){
        owner Oser=studentService.showUser(o_id);
        model.addAttribute("Oser",Oser);
        return "tuizu";
    }


//租客的查询
    @RequestMapping("zhuke")
    public String showUpdateAdmi(int o_id,Model model){
        owner Oser=studentService.showUser(o_id);
        model.addAttribute("Oser",Oser);
        return "zukexinxi";
    }

//用户的修改和租户的改变
    @RequestMapping("shomin")
    public String showAddadmin(Model model){
        List<houses> houses=housesService.linn();
        model.addAttribute("houses",houses);
        return "linxg";
    }


    @ResponseBody
    @RequestMapping("updaAdmins")
    public String update(owner Owner){
        int i=studentService.updaAdmin(Owner);
        if(i>0){
            return "ok";
        }else{
            return "no";
        }
    }



//修改
    @ResponseBody
    @RequestMapping("updaAdmin")
    public String updateAdmin(owner Owner){
        int i=studentService.updaAdmin(Owner);
        if(i>0){
            return "ok";
        }else{
            return "no";
        }
    }
}
